package bytezero.threadexer;

/**
 *  创建两个分线程,其中一个线程遍历100以内的偶数,另一个线程遍历100以内的奇数
 *
 *
 * @author Bytezero1·zhenglei!    Email:420498246@qq.com
 * create  2021-10-15 10:45
 */



public class ThreadDemo {
    public static void main(String[] args) {
//        MyThreadEven e1 = new MyThreadEven();
//        MyThreadOdd o1 = new MyThreadOdd();
//
//        e1.start();
//        o1.start();

        //创建 Thread类的拿匿名子类的方式
        new Thread(){
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    if( i % 2 ==0){
                        System.out.println(Thread.currentThread().getName()+":"+i);
                    }
                }
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {

                    if(i %2 != 0){
                        System.out.println(Thread.currentThread().getName()+":"+i);
                    }
                }
            }
        }.start();

    }
}

class MyThreadEven extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if( i % 2 ==0){
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        }
    }
}

class MyThreadOdd extends  Thread{

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {

            if(i %2 != 0){
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        }
    }
}